package yichang;
import java.util.Scanner;
public class Person {
    private String  name="";
    private int age;
    private String sex="男";
    public void setSex(String sex) throws Exception{//throws抛出异常
        if("男".equals(sex)||"女".equals(sex))
            this.sex=sex;
        else{
            throw  new Exception("性别必须是男或者女");
        }
    }
    //抽象方法
    public void print(){
        System.out.println(this.name+"("+this.sex+",  "+this.age+"岁)");
    }
    public static void main(String[] args){
        //创建对像和实例化对象
    Person person=new Person();
    try{
        person.setSex("Male");
        person.print();
    }catch(Exception e){//捕获异常
        e.printStackTrace();
    }
}
}
